package my.utils;

import java.util.Arrays;
import java.util.List;

import javax.xml.namespace.QName;

import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class WebServiceUtil {
	private static final Log log = LogFactory.getLog(WebServiceUtil.class);
	public static String namespaceURI = "http://webservice.ubce.sinodata.net.cn";
//	public static String namespaceURI = "http://com.sinodata.service/xsd";
	

	public static Object[] send(String url, String namespaceURI, String method, List<String> params) {
		log.info("**********开始发送webservice*************");
		try {
			log.info(">>>url:" + url);
			log.info(">>>method:" + method);
			log.info(">>>params:" + params.get(0).toString());
			RPCServiceClient client = new RPCServiceClient();
			Options options = client.getOptions();
			EndpointReference epf = new EndpointReference(url);
			options.setTo(epf);
			QName qname = new QName(namespaceURI, method);
			// 指定调用的方法和传递参数数据，及设置返回值的类型
			Class[] clazzs = new Class[params.size()];
			Arrays.fill(clazzs, String.class);
			Object[] result = client.invokeBlocking(qname, params.toArray(), clazzs);
			log.info(">>>返回:" + result[0]);
			log.info("**********发送完毕webservice*************");
			return result;
		} catch (Exception ex) {
			log.error("执行webservice错误:",ex);
//			IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID,  IStatus.ERROR, ex.toString(), ex);
//			ErrorDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "执行webservice错误", "执行webservice错误\n\n\t1.请检查wsdl地址是否正确.\n\t2.请确保启动webservice服务", status);
		}
		return null;
	}
}
